package com.chenhs.oop.study.多线程;

import java.sql.SQLOutput;

/**
 * @program: JAVA300
 * @description: 分类
 *  分为用户线程和守护线程
 *
 * @author: peanut
 * @create: 2019-07-21 13:39
 */
public class Demo4 implements Runnable {


    public static void main(String[] args) {
        /*当用户线程结束后，守护线程也会结束（不是立即。）*/
        Demo4 demo4 = new Demo4();
        Thread thread = new Thread(demo4,"用户线程");
        Thread thread2 = new Thread(demo4,"守护线程");
        thread2.setDaemon(true);
        thread2.start();
        thread.start();


    }

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            if(Thread.currentThread().getName().equals("用户线程") && i==300 ){
                System.out.println("用户线程结束-------------------------------------------");
                break;
            }
            System.out.println("线程名：" + Thread.currentThread().getName()+"--"+i);
        }
    }
}
